﻿using System.Drawing;
using GameLogic;
using System.Windows.Forms;
using GameLogic.Poker;

namespace Interface
{
	//TODO: GoF, запахи кода/тестов, Кент Бек (TDD), 
	//SOLID
	//IoC <- внедрить Dependency Injection Container

    public class ImageLoader : IImageLoader
    {
    	private readonly IImageCache imageCache = new ImageCache();
		private readonly IImagePathSetting pathSetting= new ImagePathSetting();
	
		public Image LoadShirt()
		{
			return GetOrAddImage(pathSetting.ShirtGetPath());
		}

        public Image LoadCard(Card card)
        {
            if (card.State==State.Up)
                return GetOrAddImage(pathSetting.CardGetPath(card));
            else
            {
                return LoadShirt();
            }
        }

		public Image LoadChips(int rate)
		{
			return GetOrAddImage(pathSetting.ChipsGetPath(rate));
		}

        public Image LoadTableChips()
        {
            return GetOrAddImage(pathSetting.TableChipsGetPath());
        }


    	private Image GetOrAddImage(string filename)
    	{
    		Image image;
    		if (imageCache.TryGet(filename, out image))
    			return image;
    		image = Image.FromFile(filename, true);
    		imageCache.Add(filename, image);
    		return image;
    	}
    }
}
